package com.sc.nft.admin.consume;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.Map;

public class test {


    public static void main(String[] args) {
        List<String> zxs = Lists.newArrayList("上海市","北京市","天津市","重庆市");
        String sqlPanel = "insert into sc_administrative_area (province,city,area,code,is_delete,create_time,modify_time,create_id,modify_id) values ({},{},{},{},{},{},{},{},{});";
        try {
            BufferedReader reader = new BufferedReader(new FileReader("C://json.json"));
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            String longString = sb.toString();
            JSONObject province = JSONObject.parseObject(longString);
            for (Map.Entry<String, Object> provinceEntry : province.entrySet()) {
                String[] p  = provinceEntry.getKey().split("&");
                if(zxs.contains(p[0])){
                    System.out.println(StrUtil.format(sqlPanel,"'"+p[0]+"'","'"+p[0]+"'",null,p[1].substring(0,4),0,"now()","now()",0,0));
                }else{
                    System.out.println(StrUtil.format(sqlPanel,"'"+p[0]+"'",null,null,p[1].substring(0,2),0,"now()","now()",0,0));
                }
                JSONObject city = JSONObject.parseObject(provinceEntry.getValue().toString());
                for (Map.Entry<String, Object> cityEntry : city.entrySet()) {
                    String[] c  = cityEntry.getKey().split("&");
                    if(zxs.contains(p[0])){
                        System.out.println(StrUtil.format(sqlPanel,"'"+p[0]+"'","'"+p[0]+"'","'"+c[0]+"'",c[1].substring(0,6),0,"now()","now()",0,0));
                    }else{
                        System.out.println(StrUtil.format(sqlPanel,"'"+p[0]+"'","'"+c[0]+"'",null,c[1].substring(0,4),0,"now()","now()",0,0));
                    }
                    JSONObject area = JSONObject.parseObject(cityEntry.getValue().toString());
                    for (Map.Entry<String, Object> areaEntry : area.entrySet()) {
                        if(zxs.contains(p[0])){

                        }else{
                            String[] a  = areaEntry.getKey().split("&");
                            System.out.println(StrUtil.format(sqlPanel,"'"+p[0]+"'","'"+c[0]+"'","'"+a[0]+"'",a[1],0,"now()","now()",0,0));
                        }

                    }
                }
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
